#ifndef OVERLAY_H
#define OVERLAY_H

#include <QMainWindow>
#include <QList>
#include <QDrag>
#include <QMimeData>
#include <QKeyEvent>
#include <QTimer>

#include "MonsterWidget.h"
#include "MainWindow.h"
#include "Settings.h"
#include "Switcher.h"
#include "WidgetFade.h"
#include "ChangeWindow.h"

namespace Ui {
    class OverlayWindow;
}

class OverlayWindow : public QMainWindow
{
    Q_OBJECT

public:
    enum CursorType{
        cursorNormal,
        cursorMove
    };
    explicit OverlayWindow(Settings * settings, MainWindow * mainWindow, QWidget *parent = 0);
    ~OverlayWindow();


    /*
     *  Function to pause the thread without blocking the UI
     *  @param unsigned long msecs : Miliseconds to sleep
     */
    void msleep(unsigned long msecs);


    /*
     *  Function to add the monsters widget to the overlay
     */
    void addMonsters();


    /*
     *  Function to delete all the monsters widget of the overlay
     */
    void deleteMonsters();

    /*
     *  Function to add the switcher button to the overlay
     */
    void addSwitcher();


    /*
     *  Function to open the window
     */
    void openWindow();

    /*
     *  Function to close the window
     */
    void closeWindow();

    /*
     *  Function to set the background transparent
     *  @param bool : True = the background will be transparent, False = the background will be visible
     */
    void setTransparentBackground(bool);

    /*
     *  Function called when a mouse click on the window
     *  @param QMouseEvent *event : the event
     */
    void mousePressEvent(QMouseEvent *event);


    /*
     *  Function called when a mouse release on the window
     *  @param QMouseEvent *event : the event
     */
    void mouseReleaseEvent(QMouseEvent *event);


    /*
     *  Function called when a mouse move over the window
     *  @param QMouseEvent *event : the event
     */
    void mouseMoveEvent(QMouseEvent *event);

    /*
     *  Function called when a key is pressed
     *  @param QMouseEvent *event : the event
     */
    void keyPressEvent(QKeyEvent *event);

    /*
     *  Function called when a key is released
     *  @param QMouseEvent *event : the event
     */
    void keyReleaseEvent(QKeyEvent *event);

    /*
     *  Function to set all the monster of all the widget alive and so kill all the timer threads
     */
    void setAllMonstersAlive();

    /*
     *  Function to change the current cursor
     *  @param OverlayWindow::CursorType cursorType : Type of the cursor
     */
    void setCursorType(OverlayWindow::CursorType cursorType);

    /*
     *  Function to check if the cursor is hover a specified object
     *  @param QMouseEvent *event : the event containing the mouse position
     *  @param QWidget * widget : the object
     *  @return bool : Boolean if the cursor is hover or not
     */
    bool isCursorOverIt(QMouseEvent *event, QWidget * widget);

public slots:
    void slotGameModChanged();

signals:
    void signalSleepEnd();

private:
    bool isClicked;                             //Boolean if a mouse is currently clicking on the window
    Settings * settings;                        //Pointer to the settings
    MainWindow * mainWindow;                    //Pointer to the mainWindow
    Ui::OverlayWindow *ui;                      //POinter to the UI
    QList<MonsterWidget *> * monstersWidgets;   //List of the current monster objects
    int clickCursorX;                           //X coordinate of the last click
    int clickCursorY;                           //Y coordinate of the late click
    bool isCtrlPressed;                         //Boolean if the Ctrl key is currently pressed
    Switcher * switcher;                        //Pointer to the Switcher object
    WidgetFade * fade;                          //Pointer to the fading thread
    ChangeWindow * changeWindow;                //Pointer to the changing window thread
};

#endif // OVERLAY_H
